//
//  UIViewController+WY.m
//  WYModel
//
//  Created by ios on 2017/3/6.
//  Copyright © 2017年 Wy. All rights reserved.
//

#import "UIViewController+WY.h"

@implementation UIViewController (WY)

- (void)navigationBarGradualChangeWithScrollView:(UIScrollView *)scrollView titleView:(UIView *)titleView offset:(CGFloat)offset color:(UIColor *)color {
    
    [self viewWillLayoutSubviews];//  布局子视图
    [self setAutomaticallyAdjustsScrollViewInsets:NO]; //
    [self.navigationController.navigationBar setUserInteractionEnabled:scrollView.contentOffset.y > offset ? YES : NO];
    
    float alpha = 1 - ((offset - scrollView.contentOffset.y) / offset);
    [self setNavigationBarColor:color alpha:alpha];
    titleView.alpha = alpha;
}


- (void)setNavigationBarColor:(UIColor *)color alpha:(CGFloat)alpha {
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageFromColor:[color colorWithAlphaComponent:alpha > 0.95f ? 0.95f : alpha]] forBarMetrics:UIBarMetricsDefault];
    
//    if (self.navigationController.viewControllers.count > 1) {
//        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
//        view.backgroundColor = color; [self.view addSubview:view];
//    }
    
}


@end
